package com.manage.service.impl;

import com.manage.dao.IEmpDao;
import com.manage.domain.Constants;
import com.manage.domain.Dept;
import com.manage.domain.Emp;
import com.manage.service.IDeptService;
import com.manage.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmpServiceImpl implements IEmpService {

    @Autowired
    private IEmpDao empDao;
    @Autowired
    private IDeptService deptService;

    @Override
    public List<Emp> list() {
        return empDao.list();
    }

    @Override
    public void add(Emp emp) {
        // 如果没有设置密码，使用默认密码
        if (emp.getPassword() == null || emp.getPassword().trim().isEmpty()) {
            emp.setPassword(Constants.DEFAULT_PASSWORD);
        }
        empDao.insert(emp);
    }

    @Override
    public void update(Emp emp) { empDao.update(emp); }

    @Override
    public void delete(Integer id) { empDao.deleteById(id); }

    @Override
    public List<Dept> getAllDepts() {
        return deptService.list();
    }
}


